home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / mac_file / vendor_d / neuralwa / nw2v50 / demo_net / conv.c < prev    next >
C/C++ Source or Header  |  1993-08-23  |  4KB  |  108 lines

  1. /*  10:15 04-Jul-88  (conv.c)  Convert RAW Stock Prices to Scaled Prices */
  2.  
  3. /************************************************************************
  4.  * Copyright(C) 1987-1992 NeuralWare Inc                                *
  5.  * Penn Center West, IV-227, Pittsburgh, PA 15276                       *
  6.  * Telephone: (412) 787-8222    FAX: (412) 787-8220                     *
  7.  *                                                                      *
  8.  * All rights reserved.  No part of this program may be reproduced,     *
  9.  * stored in a retrieval system, or transmitted, in any form or by any  *
  10.  * means, electronic, mechanical, photocopying, recording or otherwise  *
  11.  * without the prior written permission of the copyright owner,         *
  12.  * NeuralWare, Inc.                                                     *
  13.  *                                                                      *
  14.  *                          PROPRIETARY NOTICE                          *
  15.  *                                                                      *
  16.  * This document is the property of NeuralWare, Inc. and contains       *
  17.  * trade-secrets and other proprietary information.  The information    *
  18.  * herein is reserved as proprietary to NeuralWare, and is not to be    *
  19.  * published, reproduced, copied, disclosed, used, or reverse           *
  20.  * engineered without the express written consent of a duly authorized  *
  21.  * representative of NeuralWare.                                        *
  22.  ************************************************************************
  23.  */
  24.  
  25. /************************************************************************
  26.  *                  *
  27.  *  Convert RAW stock prices to SCALED stock prices     *
  28.  *                  *
  29.  ************************************************************************
  30.     To use this program:
  31.  
  32.   CONV input.file output.file
  33.  
  34.     It will take the input file, one data item per input line, and
  35.     re-scale them to the range 0.1 to 0.9.  This was used for both
  36.     the stock prediction and noise filtering examples.  In the case of
  37.     noise filtering, only the output files are provided.
  38.  
  39.     If no arguments are given, it assumes "sp500.nnz" as input and
  40.     "sp500.in" for output.
  41.  */
  42.  
  43. #include <stdio.h>
  44. #undef max
  45. #undef min
  46.  
  47. main( ac, av )
  48. int     ac;   /* # of input arguments */
  49. char    **av;   /* array of pointers to the arguments */
  50. {
  51.     FILE   *ifp;    /* input file pointer */
  52.     FILE   *ofp;    /* output file pointer */
  53.     float  flt;   /* work number for sscanf */
  54.     double   max, min;  /* max and min of input */
  55.     double   scale, offset; /* computed scale and offset */
  56.     char  *ifn, *ofn; /* input file name and output file name */
  57.  
  58.     if ( ac > 2 ) {
  59.   ifn = av[1];
  60.   ofn = av[2];
  61.     } else {
  62.   ifn = "sp500.nnz";
  63.   ofn = "sp500.in";
  64.     }
  65.     ifp = fopen( ifn, "r" );    /* raw input prices */
  66.     ofp = fopen( ofn, "w" );    /* scaled output prices */
  67.  
  68.     if ( ifp == (FILE *)0 ) {
  69.   fprintf( stderr, "Could not open input file <%s>\n", ifn );
  70.   exit( 1 );
  71.     }
  72.  
  73.     if ( ofp == (FILE *)0 ) {
  74.   fprintf( stderr, "Could not open output file <%s>\n", ifn );
  75.   exit( 1 );
  76.     }
  77.  
  78.     /* compute the minimum and maximum price in the input file */
  79.  
  80.     max = 0.0;
  81.     min = 9999999.0;
  82.     while( fscanf( ifp, "%f", &flt ) == 1 ) {
  83.   if ( flt < min )  min = flt;
  84.   if ( flt > max )  max = flt;
  85.     }
  86.  
  87.     /* compute scaling so that new prices vary from 0.1 to 0.9 */
  88.  
  89.     scale  = 0.8 / (max - min);
  90.     offset = 0.1 - scale * min;
  91.  
  92.     /* tell the user what scale and offset we are using */
  93.  
  94.     fprintf( stderr, "scale = %.4f, offset = %.4f\n", scale, offset );
  95.  
  96.     /* re-parse the input file and convert prices */
  97.  
  98.     fseek( ifp, 0l, 0 );
  99.     while( fscanf( ifp, "%f", &flt ) == 1 ) {
  100.   fprintf( ofp, "%.3f\n", flt*scale + offset );
  101.     }
  102.  
  103.     /* close the input and output files */
  104.  
  105.     fclose( ifp );
  106.     fclose( ofp );
  107. }
  108.